home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / site / Win32 / Pipe.pm < prev    next >
Encoding:
Perl POD Document  |  1999-12-28  |  3.6 KB  |  168 lines

  1. package Win32::Pipe;
  2.  
  3. $VERSION = '0.02';
  4.  
  5.  
  6. require Exporter;
  7. require DynaLoader;
  8.  
  9. @ISA= qw( Exporter DynaLoader );
  10. @EXPORT = qw();
  11.  
  12. $ErrorNum = 0;
  13. $ErrorText = "";
  14.  
  15. sub new
  16. {
  17.     my ($self, $Pipe);
  18.     my ($Type, $Name, $Time) = @_;
  19.  
  20.     if (! $Time){
  21.         $Time = DEFAULT_WAIT_TIME;
  22.     }
  23.     $Pipe = PipeCreate($Name, $Time);
  24.     if ($Pipe){
  25.         $self = bless {};
  26.         $self->{'Pipe'} = $Pipe;
  27.     }else{
  28.         ($ErrorNum, $ErrorText) = PipeError();
  29.         return undef;
  30.     }
  31.     $self;
  32. }
  33.  
  34. sub Write{
  35.     my($self, $Data) = @_;
  36.     $Data = PipeWrite($self->{'Pipe'}, $Data);
  37.     return $Data;
  38. }
  39.  
  40. sub Read{
  41.     my($self) = @_;
  42.     my($Data);
  43.     $Data = PipeRead($self->{'Pipe'});
  44.     return $Data;
  45. }
  46.  
  47. sub Error{
  48.     my($self) = @_;
  49.     my($MyError, $MyErrorText, $Temp);
  50.     if (! ref($self)){
  51.         undef $Temp;
  52.     }else{
  53.         $Temp = $self->{'Pipe'};
  54.     }
  55.     ($MyError, $MyErrorText) = PipeError($Temp);
  56.     return wantarray? ($MyError, $MyErrorText):"[$MyError] \"$MyErrorText\"";
  57. }
  58.  
  59.  
  60. sub Close{
  61.     my ($self) = shift;
  62.     PipeClose($self->{'Pipe'});
  63. }
  64.  
  65. sub Connect{
  66.     my ($self) = @_;
  67.     my ($Result);
  68.     $Result = PipeConnect($self->{'Pipe'});
  69.     return $Result;
  70. }
  71.  
  72. sub Disconnect{
  73.     my ($self, $iPurge) = @_;
  74.     my ($Result);
  75.     if (! $iPurge){
  76.         $iPurge = 1;
  77.     }
  78.     $Result = PipeDisconnect($self->{'Pipe'}, $iPurge);
  79.     return $Result;
  80. }
  81.  
  82. sub BufferSize{
  83.     my($self) = @_;
  84.     my($Result) =  PipeBufferSize($self->{'Pipe'});
  85.     return $Result;
  86. }
  87.  
  88. sub ResizeBuffer{
  89.     my($self, $Size) = @_;
  90.     my($Result) = PipeResizeBuffer($self->{'Pipe'}, $Size);
  91.     return $Result;
  92. }
  93.  
  94.  
  95. sub DESTROY
  96. {
  97.     my ($self) = shift;
  98.     Close($self);
  99. }
  100.  
  101.  
  102. sub Credit{
  103.     my($Name, $Version, $Date, $Author, $CompileDate, $CompileTime, $Credits) = Win32::Pipe::Info();
  104.     my($Out, $iWidth);
  105.     $iWidth = 60;
  106.     $Out .=  "\n";
  107.     $Out .=  "  +". "=" x ($iWidth). "+\n";
  108.     $Out .=  "  |". Center("", $iWidth). "|\n";
  109.     $Out .=  "  |" . Center("", $iWidth). "|\n";
  110.     $Out .=  "  |". Center("$Name", $iWidth). "|\n";
  111.     $Out .=  "  |". Center("-" x length("$Name"), $iWidth). "|\n";
  112.     $Out .=  "  |". Center("", $iWidth). "|\n";
  113.  
  114.     $Out .=  "  |". Center("Version $Version ($Date)", $iWidth). "|\n";
  115.     $Out .=  "  |". Center("by $Author", $iWidth). "|\n";
  116.     $Out .=  "  |". Center("Compiled on $CompileDate at $CompileTime.", $iWidth). "|\n";
  117.     $Out .=  "  |". Center("", $iWidth). "|\n";
  118.     $Out .=  "  |". Center("Credits:", $iWidth). "|\n";
  119.     $Out .=  "  |". Center(("-" x length("Credits:")), $iWidth). "|\n";
  120.     foreach $Temp (split("\n", $Credits)){
  121.         $Out .=  "  |". Center("$Temp", $iWidth). "|\n";
  122.     }
  123.     $Out .=  "  |". Center("", $iWidth). "|\n";
  124.     $Out .=  "  +". "=" x ($iWidth). "+\n";
  125.     return $Out;
  126. }
  127.  
  128. sub Center{
  129.     local($Temp, $Width) = @_;
  130.     local($Len) = ($Width - length($Temp)) / 2;
  131.     return " " x int($Len) . $Temp . " " x (int($Len) + (($Len != int($Len))? 1:0));
  132. }
  133.  
  134.  
  135. sub AUTOLOAD {
  136.  
  137.     my($constname);
  138.     ($constname = $AUTOLOAD) =~ s/.*:://;
  139.     $!=0;
  140.     $val = constant($constname, @_ ? $_[0] : 0);
  141.  
  142.     if ($! != 0) {
  143.     if ($! =~ /Invalid/) {
  144.         $AutoLoader::AUTOLOAD = $AUTOLOAD;
  145.         goto &AutoLoader::AUTOLOAD;
  146.     }
  147.     else {
  148.  
  149.         $pack = 0;
  150.         ($pack,$file,$line) = caller;
  151.             print "Your vendor has not defined Win32::Pipe macro $constname, used in $file at line $line.";
  152.     }
  153.     }
  154.     eval "sub $AUTOLOAD { $val }";
  155.     goto &$AUTOLOAD;
  156. }
  157.  
  158. bootstrap Win32::Pipe;
  159.  
  160.  
  161.  
  162.  
  163. 1;
  164. __END__
  165.  
  166.  
  167.  
  168.